﻿#include "FITKAbaqusHDF5AdaptorConnectorAssignment.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Reader.h"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Writer.h"
#include "FITK_Interface/FITKInterfaceModel/FITKCoordinateSystem.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorAssignment.h"

namespace IO
{
    QString FITKAbaqusHDF5AdaptorConnectorAssignment::getAdaptorClass()
    {
        return "FITKAbaqusHDF5AdaptorConnectorAssignment";
    }

    bool FITKAbaqusHDF5AdaptorConnectorAssignment::adaptR()
    {
        auto ca = dynamic_cast<Interface::FITKAbaConnectorAssignment*>(_dataObj);
        if (!_reader || !ca || !_h5Group) return false;
        bool isR = true;
        isR &= readConnectorAssignment(ca, *_h5Group);
        return isR;
    }

    bool FITKAbaqusHDF5AdaptorConnectorAssignment::adaptW()
    {
        auto ca = dynamic_cast<Interface::FITKAbaConnectorAssignment*>(_dataObj);
        if (!_writer || !ca || !_h5Group) return false;
        bool isW = true;
        isW &= writeConnectorAssignment(ca, *_h5Group);
        return isW;
    }

    bool FITKAbaqusHDF5AdaptorConnectorAssignment::readConnectorAssignment(Interface::FITKAbaConnectorAssignment * connectorAssignmnt, H5::Group & h5Group)
    {
        if (!connectorAssignmnt) return false;
        bool isR = true;
        isR &= FITKInterfaceHDF5AdaptorSectionAssign::readSectionAssign(connectorAssignmnt, h5Group);
        if (!isR)  return false;
        int csysID1 = readIntAttribute(h5Group, "csysID1");
        connectorAssignmnt->setCsysId1(csysID1);
        int csysID2 = readIntAttribute(h5Group, "csysID2");
        connectorAssignmnt->setCsysId2(csysID2);
        return isR;
    }

    bool FITKAbaqusHDF5AdaptorConnectorAssignment::writeConnectorAssignment(Interface::FITKAbaConnectorAssignment * connectorAssignmnt, H5::Group & h5Group)
    {
        if (!connectorAssignmnt) return false;
        bool isW = true;
        isW &= FITKInterfaceHDF5AdaptorSectionAssign::writeSectionAssign(connectorAssignmnt, h5Group);
        if (!isW)  return false;
        int csysID1 = connectorAssignmnt->getCsysId1();
        writeIntAttribute(_h5CreateGroup, "csysID1", &csysID1);
        int csysID2 = connectorAssignmnt->getCsysId2();
        writeIntAttribute(_h5CreateGroup, "csysID2", &csysID2);
        return isW;
    }

}


